package 剑指offer;

public class Offer11_JZ06 {

    public static int minNumberInRotateArray(int [] array) {
        if (array.length == 0) return 0;
        // [3,4,5,1,2]
        int left = 0; int right = array.length-1;
        while (left < right) {
            int mid = (left + right) / 2;
            if (array[mid] > array[left]) { // 说明最小值在mid右边
                left = mid;
            } else if (array[mid] < array[right]) {
                right = mid;
            } else if (right - left == 1) {
                return array[right];
            }
        }
        return array[left];
    }

    public static void main(String[] args) {
        System.out.println(minNumberInRotateArray(new int[]{1, 2, 3}));
    }
}

